package com.woniu.park.controller;

import com.woniu.park.exception.BannerException;
import com.woniu.park.log.SystemControllerLog;
import com.woniu.park.pojo.Banner;
import com.woniu.park.service.BannerService;
import com.woniu.park.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张洛诚
 * @date 2019/8/29 20:05:45
 * @description
 */
@RestController
@Api(tags = "轮播图")
public class BannerController {

    @Autowired
    BannerService bannerService;
    @SystemControllerLog(description = "首页展示轮播图片")
    @ApiOperation(value = "根据TypeId查询轮播图",notes="根据TypeId查询轮播图")
    @ApiImplicitParam(name = "typeId",value = "用户类型ID",required = true,dataType = "Integer",paramType = "path")
    @GetMapping("/getBannersByTypeId/{typeId}")
    public JsonResult<List> getBannersByTypeId(@PathVariable("typeId") Integer typeId){

        List<Banner> banners = null;
        try {
            banners = bannerService.getBannersByTypeId(typeId);
        } catch (BannerException e) {
            e.printStackTrace();
            return new JsonResult<>(JsonResult.OTHER,e.getMessage(),null);
        }
        return new JsonResult<List>(banners);
    }

}
